<template>
  <div class="page-container">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>网关列表</span>
          <el-button type="primary" @click="handleAdd">新增网关</el-button>
        </div>
      </template>

      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="id" label="ID" width="80" />
        <el-table-column prop="gatewayCode" label="网关编号" width="150" />
        <el-table-column prop="gatewayName" label="网关名称" />
        <el-table-column prop="ipAddress" label="IP地址" />
        <el-table-column prop="location" label="安装位置" />
        <el-table-column prop="status" label="在线状态">
          <template #default="{ row }">
            <el-tag :type="row.status === '在线' ? 'success' : 'danger'">
              {{ row.status }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="deviceCount" label="设备数量" />
        <el-table-column prop="lastOnlineTime" label="最后在线时间" />
        <el-table-column label="操作" width="200">
          <template #default="{ row }">
            <el-button size="small" @click="handleEdit(row)">编辑</el-button>
            <el-button size="small" type="danger" @click="handleDelete(row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        v-model:current-page="currentPage"
        :page-size="10"
        :total="50"
        layout="total, prev, pager, next"
        style="margin-top: 20px; justify-content: flex-end;"
      />
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'

const currentPage = ref(1)

const tableData = ref([
  { id: 1, gatewayCode: 'GW-001', gatewayName: '一号网关', ipAddress: '192.168.1.101', location: '配电间1号', status: '在线', deviceCount: 12, lastOnlineTime: '2024-10-27 14:30' },
  { id: 2, gatewayCode: 'GW-002', gatewayName: '二号网关', ipAddress: '192.168.1.102', location: '配电间2号', status: '在线', deviceCount: 8, lastOnlineTime: '2024-10-27 14:28' },
  { id: 3, gatewayCode: 'GW-003', gatewayName: '三号网关', ipAddress: '192.168.1.103', location: '配电间3号', status: '离线', deviceCount: 15, lastOnlineTime: '2024-10-27 10:15' },
  { id: 4, gatewayCode: 'GW-004', gatewayName: '四号网关', ipAddress: '192.168.1.104', location: '大楼A栋', status: '在线', deviceCount: 20, lastOnlineTime: '2024-10-27 14:29' },
  { id: 5, gatewayCode: 'GW-005', gatewayName: '五号网关', ipAddress: '192.168.1.105', location: '大楼B栋', status: '在线', deviceCount: 18, lastOnlineTime: '2024-10-27 14:31' }
])

const handleAdd = () => {
  ElMessage.info('新增网关功能')
}

const handleEdit = (row) => {
  ElMessage.info(`编辑网关：${row.gatewayName}`)
}

const handleDelete = (row) => {
  ElMessage.warning(`删除网关：${row.gatewayName}`)
}
</script>

<style scoped>
.page-container {
  width: 100%;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
